﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using BusinessEntityObjects;
using DataLayer; 

namespace BusinessLayer
{

    [System.ComponentModel.DataObject()]
    public class ContactBLL
    {

        #region " Constructors "

        public ContactBLL()
        {
        }

        #endregion

        #region " Methods "

        public int Count()
        {
            return ContactDAL.CreateInstance().Count();
        }

        public Contact Create()
        {

            Contact obj = new Contact();
            obj.ActiveRuleSet = "Insert";
            obj.CheckAllRules();
            return obj;
        }

        public static ContactBLL CreateInstance()
        {
            return new ContactBLL();
        }

        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public int Delete(Contact obj)
        {
            return ContactDAL.CreateInstance().Delete(obj);
        }

        public List<ContactSearchResult> FillDropDown()
        {
            return ContactDAL.CreateInstance().FillDropDown();
        }

        public List<ContactFeed> GetFeeds()
        {
            return ContactDAL.CreateInstance().GetFeeds();
        }

        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public int Insert(Contact obj, ref int intNewId)
        {

            if (obj.HasBeenValidated)
            {
                return ContactDAL.CreateInstance().Insert(obj, ref intNewId);
            }

            else
            {
                throw new InvalidOperationException("Contact has not yet been validated for insert.");
            }

        }

        public List<ContactSearchResult> SearchByLastName(string strSearchString)
        {
            return ContactDAL.CreateInstance().SearchByLastName(strSearchString);
        }

        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, true)]
        public Contact Select(int intId)
        {

            Contact obj = ContactDAL.CreateInstance().Select(intId);

            if (obj != null)
            {
                obj.EndLoading();
            }

            return obj;
        }

        public ObservableCollection<Contact> SelectAll()
        {
            return ContactDAL.CreateInstance().SelectAll();
        }

        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, true)]
        public int Update(Contact obj)
        {

            if (obj.HasBeenValidated)
            {
                return ContactDAL.CreateInstance().Update(obj);
            }

            else
            {
                throw new InvalidOperationException("Contact has not yet been validated for update.");
            }

        }
    }

        #endregion 

}
